﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_EmplPosition实体类
public class SYS_EmplPosition
{
	private string m_EmplID;
	private string m_PositionID;
	
	public SYS_EmplPosition ()
	{
		m_EmplID="";
		m_PositionID="";
	}
	
	public string EmplID
	{
		get{return m_EmplID;}
		set{m_EmplID=value;}
	}
	public string PositionID
	{
		get{return m_PositionID;}
		set{m_PositionID=value;}
	}
}
#endregion

#region SYS_EmplPosition管理类
public partial class LogicLayer
{
	public bool AddSYS_EmplPosition(SYS_EmplPosition theSYS_EmplPosition)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_EmplPosition (EmplID,PositionID) values (@EmplID,@PositionID)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_EmplPosition.EmplID);
			db.AddInParameter(cmd, "@PositionID", DbType.String, theSYS_EmplPosition.PositionID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_EmplPosition:" + ex.Message );
			return false;
		}
	}
	
	public SYS_EmplPosition GetSYS_EmplPositionFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_EmplPosition result = new SYS_EmplPosition();
			
			if (dataReader["EmplID"] != null && dataReader["EmplID"] != System.DBNull.Value )
				result.EmplID = (string)dataReader["EmplID"];
			if (dataReader["PositionID"] != null && dataReader["PositionID"] != System.DBNull.Value )
				result.PositionID = (string)dataReader["PositionID"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_EmplPosition:" + ex.Message);
			return null;
		}
	}
	
	public SYS_EmplPosition GetSYS_EmplPosition(string EmplID,string PositionID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_EmplPosition where EmplID=@EmplID and PositionID=@PositionID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			db.AddInParameter(cmd, "@PositionID", DbType.String, PositionID);
			
			SYS_EmplPosition result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_EmplPositionFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_EmplPosition:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_EmplPosition(string EmplID,string PositionID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_EmplPosition where EmplID=@EmplID and PositionID=@PositionID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			db.AddInParameter(cmd, "@PositionID", DbType.String, PositionID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_EmplPosition:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_EmplPosition(SYS_EmplPosition theSYS_EmplPosition)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_EmplPosition set  where EmplID=@EmplID and PositionID=@PositionID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_EmplPosition.EmplID);
			db.AddInParameter(cmd, "@PositionID", DbType.String, theSYS_EmplPosition.PositionID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_EmplPosition:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_EmplPosition> ListSYS_EmplPosition()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_EmplPosition";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_EmplPosition> result = new  List<SYS_EmplPosition>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_EmplPosition obj = GetSYS_EmplPositionFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_EmplPosition:" + ex.Message);
			return null;
		}
	}
	
}
#endregion